package com.aruba.bulethoothdemoapplication.mapper;

import com.aruba.bulethoothdemoapplication.model.PrintItem;
import com.aruba.bulethoothdemoapplication.utils.printer.PrintStuff;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by aruba on 2022/4/26.
 */
public class PrintItem2PrintStuff implements Mapper<List<PrintItem>, List<PrintStuff>> {
    @Override
    public List<PrintStuff> mapper(List<PrintItem> prints) {
        List<PrintStuff> stuffs = new ArrayList<>();
        for (PrintItem item : prints) {
            if (item.getDoubleSize()) {//change size
                stuffs.add(new PrintStuff(PrintStuff.PrintType.ChangeSize));
            }

            PrintStuff printStuff = new PrintStuff(PrintStuff.PrintType.TextType, item.getValue());
            if (item.getType() == 1) {
                printStuff.setPrintType(PrintStuff.PrintType.ImageBase64Type);
            }
            stuffs.add(printStuff);

            if (item.getDoubleSize()) {//reset size
                stuffs.add(new PrintStuff(PrintStuff.PrintType.ResetSize));
            }
        }
        return stuffs;
    }
}
